#ifndef _PERSONTREE_H 
#define _PERSONTREE_H

#include<string>
#include<iostream>

using namespace std;

// base class Person
class Person {
  public:
    Person(int identity, string name, string sex);
    virtual void Display()=0;
    int m_identity;
    string m_name;
    string m_sex;
};

// Employee class
class Employee: public Person {
  public:
    Employee(int identity, string name, string sex, string dept);
    void Display();
  private:
    string m_dept;
};

// Teacher class
class Teacher: public Person {
  public:
    Teacher(int identity, string name, string sex, string subject);
    void Display();
  private:
    string m_subject;
};

// Student class
class Student: public Person {
  public:
    Student(int identity, string name, string sex, int grade);
    void Display();
  private:
    int m_grade;
};

class PersonTree;

class TreeNode {
    friend class PersonTree;
  public:
    TreeNode(Person *data);
  private:
    Person *m_data;
    TreeNode *lChild, *rChild;
};

class PersonTree {
  public:
    PersonTree();
    ~PersonTree();
    TreeNode* GetRoot();

    // 插入树
    void InsertTree(Person *data);
    // 中序遍历
    void InOder(TreeNode* node);
    // 查找
    void Find(int identity);
    // 删除
    void Delete(int identity);
  private:
    TreeNode* m_root;
    void Release(TreeNode* r);
    TreeNode* InsertTree(TreeNode *node, Person *data);
};

#endif
